package com.xpgk.mvc.bintoStorage;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.binShopService.ServicePartSize;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.productOutin.ProductOutin;
import com.xpgk.mvc.productSet.Product;
import com.xpgk.mvc.productStock.ProductStock;

public class BintoStorageController extends  BaseController{
	
	private  BintoStorageService  bintoStorageService ;

	public  void  index()
	{
		render("BintoStorage.html");
	}
	/**获取除疗程外产品
	 * 
	 */
	public  void  getProduct()
	{
		String  sql=getSqlMy(Product.sqlId_nolcpro);
		List<Product>  pList=Product.dao.find(sql,Code.lc_ids);
		renderJson(pList);
	}
	/**根据产品ids获取产品库存信息
	 * 
	 */
	public  void  getProInfo()
	{
		String  productIds=getPara("productIds");
		//获取当前机构ids
		String orgids=getCUserOrganIds();
		String pstSql=getSqlMy(ProductStock.sqlId_selPSByOidsAndPids);
		ProductStock  pst=ProductStock.dao.findFirst(pstSql,orgids,productIds);
		Product  p=Product.dao.findById(productIds);
		if(pst!=null)
		{
			renderJson(pst);
		}else
		{
			Map<String,String>  mm=new HashMap<>();
			mm.put("proids", p.getStr(Product.column_ids));
			mm.put("proname", p.getStr(Product.column_name));
			mm.put("typeids", p.getStr(Product.column_typeIds));
			mm.put("productclass", p.getType().getStr(Code.column_name));
			mm.put("stocknow", "0");
			renderJson(mm);
		}
		
		
	}
	
	
	/**保存产品入库
	 * 
	 */
	@Before(Tx.class)
	public  void  saveBintoStorage()
	{	
		String  bintoDate=getPara("date");
		List<ProductOutin> poList = getModels(ProductOutin.class);
		//获取当前登录机构id
		String  orgids=getCUserOrganIds();
		//获取当前登陆人员id
		String  userids=getCUserIds();
		
		
		String msg=bintoStorageService.saveBintoStorage(poList,orgids,userids,bintoDate);
		renderText(msg);
	}
	
}
